package com.fyt.controller.pasture;

import com.fyt.controller.utils.Result;
import com.fyt.dto.pasture.AddPastureDTO;
import com.fyt.dto.pasture.UpdatePastureDTO;
import com.fyt.service.dictionary.DictionaryService;
import com.fyt.service.dictionary.specific.AnimalvarietyService;
import com.fyt.service.pasture.CityService;
import com.fyt.service.pasture.PastureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gdy
 * @since 2023-12-20
 */
@RestController
public class PastureController {

    @Autowired
    private PastureService pastureService;
    @Autowired
    private CityService cityService;
    @Autowired
    private AnimalvarietyService animalvarietyService;

    @GetMapping("/api/pasture/getPastureList")
    Result getPastureList(@RequestParam Map<String,String> map){
        return pastureService.getPastureList(map);
    }

    /**
     * 牧场新增
     * http://localhost:4000/api/pasture/addPasture
     * @param addPastureDto
     * @return
     */
    @PostMapping("/api/pasture/addPasture")
    Result addPasture(@RequestBody @Valid AddPastureDTO addPastureDto){
//        三级地址列表
        Map<String, String> map = new HashMap<>();
        cityService.getCityByLevel(map);
//        animalvarietyService.getList(map);
        return pastureService.addPasture(addPastureDto);
    }

    /**
     * 修改牧场
     * @param
     * @return
     */
    @PutMapping("/api/pasture/updatePasture/{pId}")
    public Result updatePasture(@PathVariable Integer pId, @Valid @RequestBody UpdatePastureDTO updatePastureDTO) {
        updatePastureDTO.setPId(pId);
        return pastureService.updatePasture(updatePastureDTO);
    }
}
